#include "stdafx.h"
#include "PoseRenderableObj.h"

CPoseRenderableObj::CPoseRenderableObj()
{
	z = 0;
}
CPoseRenderableObj::CPoseRenderableObj(vector<PoseData> *_Poselist)
{
	m_Poselist = _Poselist;
	z = 0;
}
CPoseRenderableObj::CPoseRenderableObj(vector<PoseData> *_Poselist,double _z)
{
	m_Poselist = _Poselist;
	z = _z;
}
CPoseRenderableObj::~CPoseRenderableObj()
{
}

bool CPoseRenderableObj::Initialize(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
	if (isOn & !isInitialize)
	{
		if (m_Poselist==NULL)
		{
			throw "";
		}
		else
		{
			int ij = m_Poselist->size();
			m_topVertices = new PositionColored[ij];
			int i = 0;
			for (vector<PoseData>::iterator iter = m_Poselist->begin(); iter != m_Poselist->end(); ++iter)
			{
				m_topVertices[i].Position.x = (*iter).x;
				m_topVertices[i].Position.y = (*iter).y;
				m_topVertices[i].Position.z = z;
				m_topVertices[i].colour = D3DCOLOR_XRGB(255, 0, 0);
				i++;
			}
			isInitialize = true;
		}
	}
	return true;
}

void CPoseRenderableObj::Update(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
	if (isOn &!isInitialize)
	{
		Initialize(g_pd3dDevice);
	}
}

void CPoseRenderableObj::Render(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
	if (isOn & isInitialize)
	{
		int ij = m_Poselist->size();
		g_pd3dDevice->SetFVF(D3DFVF_POSITIONCOLORED);
		g_pd3dDevice->DrawPrimitiveUP(D3DPT_LINESTRIP, ij - 1, m_topVertices, sizeof(PositionColored));
	}
}
